home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / dos / dir / findnext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-29  |  2.4 KB  |  102 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <go32.h>
  7. #include <dpmi.h>
  8. #include <dir.h>
  9. #include <libc/dosio.h>
  10.  
  11. int
  12. findnext(struct ffblk *ffblk)
  13. {
  14.   __dpmi_regs r;
  15.  
  16.   if (ffblk == 0)
  17.   {
  18.     errno = EACCES;
  19.     return -1;
  20.   }
  21.  
  22.   if(_USE_LFN)
  23.   {
  24.     /* si = 1 indicates DOS style dates, 0 means Win32 type dates.
  25.        DOS style dates are broken in some Win95 betas, build for either.
  26.        Release works with DOS date, it's faster, so use it. */
  27.     #define USEDOSDATE 1
  28.     #if USEDOSDATE == 1
  29.       #define _Win32_to_DOS (long)
  30.     #else
  31.       extern long _Win32_to_DOS(long long WinTime);
  32.     #endif
  33.  
  34.     r.x.ax = 0x714f;
  35.     r.x.bx = ffblk->lfn_handle;
  36.     if(!r.x.bx)
  37.     {
  38.       errno = ENMFILE;
  39.       return 1;
  40.     }
  41.     r.x.di = __tb_offset;
  42.     r.x.es = __tb_segment;
  43.     r.x.si = USEDOSDATE;
  44.  
  45.     __dpmi_int(0x21, &r);
  46.     if (!(r.x.flags & 1))
  47.     {
  48.       struct ffblklfn ffblk32;
  49.       /* Recover results */
  50.       dosmemget(__tb, sizeof(struct ffblklfn), &ffblk32);
  51.  
  52.       ffblk->ff_attrib = (char)ffblk32.fd_attrib;
  53.       *(long *)&ffblk->ff_ftime = _Win32_to_DOS(ffblk32.fd_mtime);
  54.       ffblk->ff_fsize = ffblk32.fd_size;
  55.       strcpy(ffblk->ff_name, ffblk32.fd_longname);
  56.       *(long *)&ffblk->lfn_ctime = _Win32_to_DOS(ffblk32.fd_ctime);
  57.       *(long *)&ffblk->lfn_atime = _Win32_to_DOS(ffblk32.fd_atime);
  58.  
  59.       return 0;
  60.     }
  61.     errno = __doserr_to_errno(r.x.ax);
  62.     if (errno == ENMFILE)         /* call FindClose */
  63.     {
  64.       ffblk->lfn_handle = 0;
  65.       r.x.ax = 0x71a1;
  66.       __dpmi_int(0x21, &r);
  67.       if(r.x.flags & 1)
  68.       {
  69.         errno = __doserr_to_errno(r.x.ax);
  70.         return -1;
  71.       }
  72.       return 1;
  73.     }
  74.     return -1;
  75.   }
  76.   else
  77.   {
  78.     #define _sizeof_dos_ffblk 44
  79.     /* The 43 character ff block must be put to the DTA, make the call, then
  80.        recover the ff block. */
  81.  
  82.     r.x.dx = __tb_offset;
  83.     r.x.ds = __tb_segment;
  84.     r.h.ah = 0x1a;
  85.     __dpmi_int(0x21, &r);
  86.  
  87.     dosmemput(ffblk, sizeof(struct ffblk), __tb);
  88.  
  89.     r.h.ah = 0x4f;
  90.     __dpmi_int(0x21, &r);
  91.     if(r.x.flags & 1)
  92.     {
  93.       errno = __doserr_to_errno(r.x.ax);
  94.       return -1;
  95.     }
  96.  
  97.     /* Recover results */
  98.     dosmemget(__tb, _sizeof_dos_ffblk, ffblk);
  99.     return 0;
  100.   }
  101. }
  102.